using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Cmn;
using EntLibEC.Info.Basic;
using EntLibEC.Biz;
using EntLibEC.Biz.Basic;

namespace EntLibEC.View.Basic
{
	/// <summary>
	/// Summary description for ShipTypePayTypeOpt.
	/// </summary>
	public partial class ShipTypePayTypeOpt : PageBase
	{

		private int sysno;
		private string opt;
		protected string bodyOnLoad="";
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if ( Request.QueryString["opt"] == null )
			{
				Assert(lblMessage, "opt missing", -1);
				return;
			}
			else
			{
				this.opt = Request.QueryString["opt"].ToString();
			}

			if ( Request.QueryString["sysno"] != null)
			{
				try
				{
					this.sysno = Convert.ToInt32(Request.QueryString["sysno"].ToString());
				}
				catch
				{
					Assert(lblMessage, "sysno is not an integer", -1);
					return;
				}
			}

			if ( !Page.IsPostBack)
			{
				scShipType.BindShipType(false);
				scPayType.BindPayType(false);
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnAdd_Click(object sender, System.EventArgs e)
		{
			if ( !base.CheckAccess((int)AppEnum.Privilege.AreaShipPay, false, lblMessage) )
				return;

			if ( scPayType.PayTypeSysNo == AppConst.IntNull )
			{
				Assert(lblMessage, "please select a pay type", -1);
			}
			if ( scShipType.ShipTypeSysNo == AppConst.IntNull )
			{
				Assert(lblMessage, "please select a ship type", -1);
			}

			ShipPayInfo oInfo = new ShipPayInfo();

			oInfo.ShipTypeSysNo = scShipType.ShipTypeSysNo;
			oInfo.PayTypeSysNo = scPayType.PayTypeSysNo;

			try
			{
				ASPManager.GetInstance().InsertShipPayUn(oInfo);
				
				LogManager.GetInstance().Write(new LogInfo(oInfo.SysNo, (int)AppEnum.LogType.Basic_ShipPayUn_Add, base.sInfo));
				Assert(lblMessage, "add ship ! pay ok", 1);
				bodyOnLoad = "javascript:window.opener.__doPostBack('btnSearch','btnSearch');window.close(); return false;";
			}
			catch(BizException exp)
			{
				Assert(lblMessage, exp.Message, -1);
			}
			catch(Exception exp)
			{
				Assert(lblMessage, "add ship ! pay failed, see log", -1);
				ErrorLog.GetInstance().Write(exp.ToString());
			}		
		}
	}
}
